<!--
    随机土味情话 API
    内容展示：
        用到了 卡片
-->
<template>
  <div class="container">

    <!--  面包屑导航 -->
    <nav aria-label="breadcrumb">
      <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="/onlinetool/#/">首页</a></li>
        <li class="breadcrumb-item"><a href="#">休闲娱乐</a></li>
        <li class="breadcrumb-item active" aria-current="page">土味情话</li>
      </ol>
    </nav>

    <!--  头部卡片  -->
    <div class="card border-primary ">
      <!--  放在 .card 里面的标签默认宽度会占满父元素宽度, 所以 a 标签应该放在 .card-body 里面-->
      <div class="card-header bg-info">土味情话</div>
      <div class="card-body ">
        <h5 class="card-title text-primary">随机生成一句土味情话，快发给自己喜欢的人吧~</h5>
        <p class="card-text"></p>
        <button type="button" @click="getLoveSentence" class="btn btn-outline-success">生成土味情话</button>

        <!--  旋转提示组件  -->
        <div class="spinner-border text-success ml-5" role="status">
          <span class="sr-only">Loading...</span>
        </div>
      </div>
    </div>

    <!--  结果内容展示：使用卡片-->
    <div class="card mt-3">
      <div class="card-body text-center text-warning font-weight-bold lead">
        {{ content }}
      </div>
    </div>

  </div>
</template>

<script>
  export default {
    name: 'LoveSentence',
    data() {
      return {
        content: ""
      }
    },
    methods: {
      async getLoveSentence() {
        this.$(".spinner-border").css("display", "inline-block");

        const result = await this.$http.get("https://api.uomg.com/api/rand.qinghua", {
          params: {
            format: "json"
          }
        });
        console.log(result);
        this.content = result.data.content;
        if (this.content !== "") {
          this.$(".spinner-border").css("display", "none");
        }
      }
    }
  }
</script>

<style scoped>
  .spinner-border {
    display: none;
  }
</style>
